package com.yenlien.traceyun.business.service.rest.usercenter;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.business.bean.RestURL;
import com.yenlien.traceyun.business.service.rest.RestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-06
 * @description:用户中心rest服务
 **/

@Service
public class UserRestService {
    @Autowired
    private RestService restService;


    public Object findByList(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/findByList", param);
    }

    public JSONObject findCountByCompanyId(String companyId) {
        return restService.getJson(RestURL.USERCENTER + "user/findCountByCompanyId/" + companyId);
    }

    public Object findByAll(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/findByAll", param);
    }

    public Object checkPassword(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/checkPassword", param);
    }

    public Object setUserAppmenus(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "resource/set/user/appmenus", param);
    }

    /**
     * 用户解锁，锁定
     *
     * @param param
     * @return
     */
    public JSONObject locked(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/locked", param);
    }

    /**
     * 导入
     *
     * @param param
     * @return
     */
    public JSONObject importUser(JSONArray param) {
        return restService.postJson(RestURL.USERCENTER + "user/import", param);
    }

    /**
     * 导出
     *
     * @param param
     * @return
     */
    public JSONObject toUser(JSONObject param) {
        return restService.postJson(RestURL.USERCENTER + "user/toUser", param);

    }


    /**
     * 加载
     *
     * @param id
     * @return
     */
    public JSONObject findById(String id) {
        return restService.getJson(RestURL.USERCENTER + "user/findById/" + id);
    }

    /**
     * 注册
     *
     * @param map
     * @return
     */
    public JSONObject save(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "user/save", map, files);
    }


    public JSONObject save2(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "user/save2", jsonObject);
    }

    /**
     * 修改
     *
     * @param map
     * @return
     */
    public JSONObject update(Map<String, Object> map, List<MultipartFile> files) {
        return restService.postForm(RestURL.USERCENTER + "user/update", map, files);
    }

    public JSONObject update2(JSONObject jsonObject) {
        return restService.postJson(RestURL.USERCENTER + "user/update2", jsonObject);
    }

    /**
     * 登录
     *
     * @param uid      用户标识
     * @param password 密码
     * @param appid    应用id
     * @return
     */
    public JSONObject login(String uid, String password, String appid) {
        JSONObject userInfo = new JSONObject();
        userInfo.put("uid", uid);
        userInfo.put("password", password);
        userInfo.put("appid", appid);
        JSONObject result = restService.postJson(RestURL.USERCENTER + "user/login", userInfo);
        return result;
    }
}
